package logic

import (
	"context"
	"doctor-medicine-system/usersrpc/usersrpc"

	"doctor-medicine-system/api/internal/svc"
	"doctor-medicine-system/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type MedicineAddLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewMedicineAddLogic(ctx context.Context, svcCtx *svc.ServiceContext) *MedicineAddLogic {
	return &MedicineAddLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *MedicineAddLogic) MedicineAdd(req *types.MedicineAddRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	add, err := l.svcCtx.UsersRpc.MedicineAdd(l.ctx, &usersrpc.MedicineAddRequest{
		Name:    req.Name,
		Content: req.Content,
		From:    req.From,
		Message: req.Name,
		Sign:    req.Sign,
		DocId:   req.DocId,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    500,
		}, nil
	}
	return &types.Response{
		Message: "添加成功",
		Data:    add,
		Code:    200,
	}, nil
}
